from PySide6.QtWidgets import QStatusBar, QLabel
from PySide6.QtCore import Qt

class StatusBar(QStatusBar):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setup_ui()
        
    def setup_ui(self):
        # 创建状态标签
        self.connection_label = QLabel()
        self.cursor_label = QLabel()
        self.terminal_type_label = QLabel("xterm")
        

        
        # 添加标签到状态栏
        self.addPermanentWidget(self.cursor_label)
        self.addPermanentWidget(self.connection_label)
        self.addPermanentWidget(self.terminal_type_label)
        
        # 设置初始状态
        self.update_status(None, None, False)
        self.update_cursor_position(1, 1)
        
    def update_status(self, session_type=None, params=None, connected=False):
        if not connected:
            self.connection_label.setText("未连接")
            return
            
        if session_type == "串口":
            status = f"串口 - {params.get('port', 'N/A')} @ {params.get('baudRate', 'N/A')}"
        elif session_type == "SSH":
            status = f"SSH - {params.get('host', 'N/A')}:{params.get('port', 'N/A')}"
        elif session_type == "Telnet":
            status = f"Telnet - {params.get('host', 'N/A')}:{params.get('port', 'N/A')}"
        else:
            status = "已连接"
            
        self.connection_label.setText(status)
        
    def update_cursor_position(self, row, col):
        """更新光标位置信息"""
        cursor_text = f"行: {row}, 列: {col}"
        self.cursor_label.setText(cursor_text)